package com.stylefeng.guns.command;

import com.stylefeng.guns.command.impl.CommandContext;
import org.springframework.stereotype.Component;

@Component
public class CommandExecute {

    public void execute(ICommand command, String key) {
        Thread thread = new Thread(command);
        thread.start();
        CommandContext.setCommand(key, thread);
    }

    public void undo(String key) {

        Thread thread = CommandContext.getCommand(key);
        thread.interrupt();
        CommandContext.removeCommand(key);
    }

}
